package org.xdq.demo.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xdq.demo.dto.EmpDto;
import org.xdq.demo.dto.EmpQueryDto;
import org.xdq.demo.model.Dep;
import org.xdq.demo.service.DepService;
import org.xdq.demo.service.EmpService;
import org.xdq.demo.vo.R;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
public class EmpController {

    @Autowired
    private DepService depService;

    @Autowired
    private EmpService empService;

    @GetMapping("/info/emp/dep")
    public R<List<Dep>> depList() {
        List<Dep> depList = depService.getAllEnableDepList();
        return R.OK(depList);
    }

    @GetMapping("/info/emp")
    public R<Map<String, Object>> empList(EmpQueryDto dto)  {

        System.out.println(empService.getClass().getName());
        if(1==1)throw new RuntimeException("测试！！！");
        Map<String, Object> empPage = empService.getEmpPage(dto);
        return R.OK(empPage);
    }

    @DeleteMapping("/info/emp")
    public R<?> deleteEmp(@RequestBody String[] ids) throws IOException {
        empService.removeEmp(ids);
        return R.OK();
    }

    @PostMapping("/info/emp")
    public R<?> addNewEmp(@RequestBody EmpDto dto) throws IOException {
        empService.addNewEmp(dto);
        return R.OK();
    }

    @PutMapping("/info/emp/confirm")
    public R<?> confirmEmp(String e_id) {
        empService.changeEmpStatus(e_id,1);
        return R.OK();
    }

}
